﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections;
using Jack.IData;
using Jack.ISpider;

namespace Jack.ITask
{
    //@jack mark 任务线程管理
    public class TaskMange : ITask
    {
        private List<WebInfo> _list = new List<WebInfo>();
        private static Task[] task;
        private SpiderManage spider;
        public TaskMange()
        {
            _list = SingletonDataInfo.Instance.WebInfoList;
            task = new Task[_list.Count];
        }

        public void Start()
        {
            if (_list.Count>0)
            {
                Parallel.For(0, _list.Count, i =>
                                                 {
                                                     task[i] = new Task(obj => SpiderForMethods((WebInfo)obj), _list[i]);
                                                     task[i].Start();
                                                 });
            }
        }

        private void SpiderForMethods(WebInfo _webinfo)
        {
            Console.WriteLine("Start------");
            Thread.Sleep(5000);
            spider = new SpiderManage(_webinfo);
            spider.CmdSpider();
        }
    }
}
